package org.yoyo.classroom.controller;

import org.yoyo.classroom.domain.po.BookingRule;
import org.yoyo.classroom.result.Result;
import org.yoyo.classroom.service.BookingRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 预约规则控制器
 */
@RestController
@RequestMapping("/booking-rule")
public class BookingRuleController {

    @Autowired
    private BookingRuleService bookingRuleService;

    /**
     * 根据ID查询预约规则
     * @param id 预约规则ID
     * @return 包含预约规则对象的结果
     */
    @GetMapping("/{id}")
    public Result<BookingRule> getBookingRuleById(@PathVariable Long id) {
        BookingRule bookingRule = bookingRuleService.getBookingRuleById(id);
        if (bookingRule != null) {
            return Result.success(bookingRule);
        } else {
            return Result.error("Booking rule not found");
        }
    }

    /**
     * 查询所有预约规则
     * @return 包含预约规则列表的结果
     */
    @GetMapping("/")
    public Result<List<BookingRule>> getAllBookingRules() {
        List<BookingRule> bookingRules = bookingRuleService.getAllBookingRules();
        return Result.success(bookingRules);
    }

    /**
     * 插入预约规则
     * @param bookingRule 预约规则对象
     * @return 包含影响行数的结果
     */
    @PostMapping("/")
    public Result<Integer> addBookingRule(@RequestBody BookingRule bookingRule) {
        int affectedRows = bookingRuleService.addBookingRule(bookingRule);
        return Result.success(affectedRows);
    }

    /**
     * 更新预约规则
     * @param bookingRule 预约规则对象
     * @return 包含影响行数的结果
     */
    @PostMapping("/updateRule")
    public Result<Integer> updateBookingRule(@RequestBody BookingRule bookingRule) {
        int affectedRows = bookingRuleService.updateBookingRule(bookingRule);
        return Result.success(affectedRows);
    }

    /**
     * 删除预约规则（逻辑删除）
     * @param id 预约规则ID
     * @return 包含影响行数的结果
     */
    @DeleteMapping("/{id}")
    public Result<Integer> deleteBookingRule(@PathVariable Long id) {
        int affectedRows = bookingRuleService.deleteBookingRule(id);
        return Result.success(affectedRows);
    }


    @PutMapping("/{ruleId}/status")
    public Result changeRuleStatus(@PathVariable("ruleId") Integer ruleId){
        return null;
    }
}
